package com.kailu.hotel.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.kailu.hotel.service.HistoryManager;
import com.kailu.hotel.service.RoomManager;
import com.kailu.hotel.service.RoomUsingManger;

/**
 * @author viet.ch
 * @generated Apr 30, 2014
 * @from VN
 */

@Controller
public class AdminController {
	
	@Autowired
	RoomUsingManger roomUsingManger;
	
	@Autowired
	RoomManager roomManager;
	
	@Autowired
	private HistoryManager historyManager;
	
	@RequestMapping("/adminblank")
    public String adminBlank()
    {
        return "admin_blank";
    }
	
	@RequestMapping("/dashboard")
    public String dashboard(ModelMap map)
    {
		map.addAttribute("room_number",roomUsingManger.getAllRoomUsing().size());
		map.addAttribute("all_room_number", roomManager.getAllRoom().size());
		map.addAttribute("historyList", historyManager.getAllHistory());
        return "dashboard";
    }
	
	@RequestMapping(value = "/login", method = RequestMethod.POST) 
	public String login(HttpServletRequest request) {
		
		String username = request.getParameter("username").toString();
		String password = request.getParameter("password").toString();
		
		System.out.println("username: " + username);
		System.out.println("password: " + password);
		
		String url = "";
		
		if (username.equals("admin") && password.equals("admin")) {
			url = "redirect:/dashboard";
		} else {
			url = "login";
		}
		return url;
	}
	
}
